04. Exercise: Create the ClippingExample Project

23 4 AAK Create Project SC

Android Developer Documentation

Exercise

In this exercise you are going to create the ClippingExample project.

  1. Create a Kotlin project called ClippingExample with the Empty Activity template. Use com.example.android for the package name prefix.

  2. Open MainActivity.kt.

  3. In the onCreate() method, replace the default content view and set the content view to a new instance of ClippedView. This will be your custom view for the clipping examples that you will create next.

setContentView(ClippedView(this))
  1. At the same level as MainActivity.kt, create a new Kotlin file and class for a custom view called ClippedView that extends View. The rest of your work will all be inside this ClippedView. The @JvmOverloads annotation instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values.
class ClippedView @JvmOverloads constructor(
   context: Context,
   attrs: AttributeSet? = null,
   defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
}